* Purpose: To study the intervention strength for info_study
* Author: Sadish
* Last Modified: 2021-04-22
* Notes:

version 13

* Inputs **************************************************************
  local data "${is_root}/6_Processed_Data/is_4_4_6_publicData.dta"
  local infoContent "${is_root}/7_Output/is_4_4_3_infoContent.gph"
  local infoTable "${is_root}/7_Output/is_4_4_3_infoTable.tex"
  local uid "empcode" // variables to uniquely identify individuals
***********************************************************************


clear all
set more off
set scheme lean1 // plottig
tempfile box

* Get Clean Data ******************************************************
use "`data'", clear
save `box', replace
***********************************************************************


* Intervention Strength ***********************************************
su smsDelivered if TM==1
su contact if VR==1
su contact if PC==1

/*
gr tw (histogram intDuration if phoneCall==1, ///
        w(20) percent lc(gs0%100) lp(l) fc(gs16%0) lw(0.5) ///
	   ) ///
      (histogram intDuration if voiceRecording==1, ///
	    w(20) percent lc(gs16%0) lp(l) fc(gs8%50) ///
	   ), legend(order(1 "Phone Call" 2 "Pre-Recorded Audio"))
*/
gr tw (histogram infoContent if phoneCall==1, ///
        w(1) percent lc(gs0%100) lp(l) fc(gs16%0) lw(0.5) ///
	   ) ///
      (histogram infoContent if voiceRecording==1, ///
	    w(1) percent lc(gs16%0) lp(l) fc(gs8%50) ///
	   ), legend(order(1 "Phone Call" 2 "Pre-Recorded Audio"))
gr save `infoContent', asis replace
*

cap: file close texFile
file open texFile using "`infoTable'", write replace
file write texFile ///
   "\begin{tabular}{a{6cm} *{3}{b{2.2cm}}} \toprule % The *{#} repeats the following argument for # columns. a{} is ragged right column, b{} is centered." _n
file write texFile " Variable & Phone Call & Pre-Recorded Audio & Difference \\ \midrule" _n

foreach v in contact infoContent infoAll infoRepeat {
  local la_`v': var lab `v'
  
  su `v' if PC==1
  local mean_PC = r(mean)
  
  su `v' if VR==1
  local mean_VR = r(mean)
  
  ttest `v' if PC==1 | VR==1, by(PC)
  local se_PC_VR = "(" + string(r(se), "%12.2fc") + ")"
  local mean_diff = `mean_PC' - `mean_VR'
  local mean_diff = string(`mean_diff', "%12.2fc")
  
  local mean_PC = string(`mean_PC', "%12.2fc")
  local mean_VR = string(`mean_VR', "%12.2fc")
  
  file write texFile "`la_`v'' & `mean_PC' & `mean_VR' & `mean_diff' \\ " _n
  file write texFile " & & & `se_PC_VR' \\ " _n
}

file write texFile "\bottomrule" _n
file write texFile "\end{tabular}" _n
file close texFile
***********************************************************************
